const App = {
  data() {
    return {
      party_member_log: { },
      personal_information :{
        ID_Card_Number:''
      },
      pageTitle:'',
      Creater:[],
      ReviewResults:[
        {
          value: "合格",
          label: "合格",
        },
        {
          value: "不合格",
          label: "不合格",
        },
      ],
      addType:'',
      fileList:[]
    };
  },
  mounted() {
//获取点击的步骤字段
    this.addType = sessionStorage.getItem("addType");
    console.log("当前传过来的字段：", this.addType);

    // let activist = sessionStorage.getItem("activist");
    // console.log(activist);
    
  },

  computed:{
    
    // formTitle() {
    //   return this.formType === 'activist' 
    //     ? '确定为入党积极分子日期' 
    //     : '确定为发展对象的日期'
    // }
  },

  methods: {

    //添加进来的方法   
    Add() {
      let condition = "Row_Status='0'";
      const _this = this;
      // 调党组织
      $.ajax({
        headers: {
          "content-type": "application/x-www-form-urlencoded",
        },
        url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
        method: "post",
        data: {
          Data: "party_organization", //表名
          Condition: condition,
        },
        success: (res) => {
          console.log("res", res);
          _this.Manager = res;
        },
        error: (err) => {
          console.log(err);
        },
      });
      //查personal_information表的lD_Card_Number
      $.ajax({
        headers: {
          "content-type": "application/x-www-form-urlencoded",
        },
        url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
        method: "post",
        data: {
          Data: "personal_information", //表名
          Condition: "Row_Status='0'",
        },
        success: (res) => {
          console.log("res", res);
          _this.Recorder = res;
          console.log(_this.Recorder);
          
        },
        error: (err) => {
          console.log(err);
        },
      });
    },

    //编辑进来方法
    Edit(key) {

      console.log(key);
      let TABLE_NAME = sessionStorage.getItem("TABLE_NAME");
      console.log(TABLE_NAME);
      // let rowkey = sessionStorage.getItem("rowkey");
      // console.log(rowkey);
      
      const _this = this;

      //先查人员表的身份证号
      $.ajax({
        headers: {
          "content-type": "application/x-www-form-urlencoded",
        },
        url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
        method: "post",
        data: {
          Data: "personal_information" , //表名
          Condition: `personal_Name='${key}'`,
          // 
        },
        success: (res) => {
          console.log('请求结果',res);
          let ID = res[0].ID_Card_Number
          console.log('id',ID)
          //通过ID查申请人表，渲染到页面
          $.ajax({
            headers: {
              "content-type": "application/x-www-form-urlencoded",
            },
            url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
            method: "post",
            data: {
              Data: TABLE_NAME, //表名
              Condition: `Applicat_SerialNumber='${ID}'`,
              // `${key}='${rowkey}'`
            },
            success: (res) => {
              console.log('1',res);
              _this.party_member_application = res[0];
            },
            error: (err) => {
              console.log(err);
            },
          });
        },
        error: (err) => {
          console.log(err);
        },
      });

      
    },
    //提交表单
    handleSubmit() {
      this.handleApplicantChange()
      let time = parseTime(new Date())
      console.log(time);
      sessionStorage.setItem('time', time)
      
      // return
      let type = sessionStorage.getItem("type");
      console.log(type);
      const appElement = document.getElementById("MainTable");
      console.log(appElement);
      let dataOptions = appElement.getAttribute("data-options");
      console.log(dataOptions);
      //动态获取到的表单数据
      let options = JSON.parse(dataOptions);
      console.log("options", options);
      let lArray = new Array();
      lArray.push(this[options.form]);
      //动态获取的表名
      let bm = options.TableName;
      console.log(bm);
      let lJSONObject = new Object();
      lJSONObject[bm] = lArray; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      if (type == "Edit") {
        lJSONObject_DataSet.Modify = lJSONObject; //换表
      } else {
        lJSONObject_DataSet.Add = lJSONObject; //换表
      }
      this.AddApi(lJSONObject_DataSet);
    },
    AddApi(lJSONObject_DataSet) {
      console.log(lJSONObject_DataSet);
      const _this = this;
      $.ajax({
        url: `${mh}/clientOperation/generalSaveForClient`,
        method: "post",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: (res) => {
          console.log(res);
          // 在普通 JavaScript 中使用 MessageBox
          ElMessage({
            message: "提交成功",
            type: "success",
            plain: true,
            duration: 1000, // 消息显示时长（毫秒）
          });
          // 等待 3 秒后回退页面
          setTimeout(() => {
            window.history.back();
          }, 1000);
        },
        error: (err) => {
          console.log(err);
        },
      });
    },
    handleChange(file, fileList) {
      console.log(file);
      
      console.log(fileList);
      
      const reader = new FileReader();
      reader.readAsDataURL(file.raw);
      reader.onload = () => {
        const base64Data = reader.result;
        console.log("Base64 编码的图片数据：", base64Data);

        
        // return
        const _this = this;
        $.ajax({
          headers: {
            "content-type": "application/json",
          },
          url: `${mh}/generalBusiness/generalSaveFilesAsImage`,
          method: "post",
          data: '{"Data":"' + base64Data + '"}',
          success: (res) => {
            console.log(res);
          },
          error: (err) => {
            console.log(err);
          },
        });
      };
      reader.onerror = () => {
        console.error("读取文件时出错");
      };
    },
    goBack() {
      window.history.back();
    },
  },
};
const { createApp, ref } = Vue;
const app = createApp(App);
app.use(ElementPlus,{locale: zhCn});
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.mount("#app");
